Código fuente de 'Reordena arrays aleatoriamente.asp'

<html>

<head>
<title>Reordena arrays aleatoriamente - Códigos asp, programacion asp, descargas asp, rutinas asp</title>
</head>

<p align="center"><b><font size="3">Reordena arrays aleatoriamente</font></b>
<body style="font-family: Arial; font-size: 11pt"></p>


<% 

Function ReOrderArrayIndexed(ByVal aArray)

  Dim iCount
  iCount = UBound(aArray)

  'Create a string of indexes
  Dim iLoop, strIndex, iUpper, iLower
  iLower = LBound(aArray)

  For iLoop = iLower to iCount
    strIndex = strIndex & CStr(iLoop)

    If iLoop < iCount then strIndex = strIndex & ","
  Next

  'Choose a Random Index
  Randomize Timer

  Dim iRnd, aTmp, iTmpUpper, strNewIndex
  Redim aTmp(iCount)

  'Iterate through, plucking out indexes from aTmp
  For iLoop = iLower to iCount
    iTmpUpper = iCount - iLoop

    'Rebuild the aTmp array
    ReDim Preserve aTmp(iTmpUpper)
    aTmp = split(strIndex, ",")

    'Choose a spot in the index array
    iRnd = Int(Rnd * (iTmpUpper + 1))

    'Build up the reordered array in string form
    strNewIndex = strNewIndex & aArray(aTmp(iRnd)) & ","

    'Remove the chosen index to the end of the array and
    'chop off the last element
    aTmp(iRnd) = aTmp(iTmpUpper)

    ReDim Preserve aTmp(iTmpUpper - 1)
    strIndex = join(aTmp, ",")
  Next

  'At this point, strNewIndex contains a comma at the end,
  'so we need to hack this off before building the array
  'with split...
  strNewIndex = Left(strNewIndex, Len(strNewIndex) - 1)

  ReOrderArrayIndexed = split(strNewIndex, ",")
End Function


response.write "<b>El vector es : </b> 14,hola,21,valencia,33,astalaweb,9,feo,11,baloncesto<br>"
response.write "<br><b>Resultado (ordena aleatoriamente): </b>"

MyArray = Array(14,"hola",21,"valencia",33,"astalaweb",9,"feo",11,"baloncesto")
MyArray = ReOrderArrayIndexed(MyArray)

For I = 0 to Ubound(MyArray)

if i<Ubound(MyArray) then 
	Response.Write MyArray(I) & "," & vbCRLF
else
	Response.Write MyArray(I) 
end if

next

response.write "<br><br>Pulsa el botón de refrescar para un nuevo resultado"
%>

</body>
</html>